using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MyMedia.iPod.Music
{
	public class AlbumList : Node
	{
		int m_albumCount;
		internal Mhla m_mhla;

		public int AlbumCount
		{
			get { return m_albumCount; }
		}

		internal override void AddChild(Node node)
		{
			base.AddChild(node);

			Database.RegisterNode(node as AlbumItem);
		}

		internal void AddSong(AlbumItem item)
		{
			base.AddChild(item);

			m_mhla.AlbumCount++;
		}

		//protected override int Size
		//{
		//    get { return m_mhla.HeaderLength; }
		//}

		protected override void ReadImpl(BinaryReader reader)
		{
			m_mhla = new Mhla();
			m_mhla.Read(reader);

			m_albumCount = m_mhla.AlbumCount;

			for (int i = 0; i < m_mhla.AlbumCount; i++)
			{
				AlbumItem item = new AlbumItem();

				// The order here is important. Load first then AddChild
				item.Read(reader);
				AddChild(item);
			}
		}

		protected override void WriteImpl(BinaryWriter writer)
		{
			m_mhla.Write(writer);
		}

		protected override void SetSize(int size)
		{
		}
	}
}
